// app.js
import {
	createStoreBindings
} from 'mobx-miniprogram-bindings'
import {
	store
} from './store/store'
import wrapRequest from './utils/request'

App({
	onLaunch() {
		var that = this
		this.storeBindings = createStoreBindings(this, {
			store,
			actions: ['updateUserInfo'],
		})
		// 登录
		wx.login({
			success: res => {
				console.log('Launch login:', res)
				if (res.code) {
					wrapRequest('/v1.0/auth/code', 'POST', {
						data: {
							code: res.code,
						},
						success: function (res) {
							console.log('http success:' + JSON.stringify(res))
							if (res.data?.data) {
								console.log('onLoad userInfo: ', res.data.data)
								that.updateUserInfo(res.data.data)
								wx.setStorageSync('userId', res.data.data.id)
							}
						},
						fail: function (e) {
							console.log('http fail:', e)
						}
					})
				} else {
					console.log("登录失败")
				}
			}
		})
	},
	globalData: {
		domain: "https://api.frozenhu.cn:8080",
		// domain: "http://127.0.0.1:7100",
		uploadDomain: "https://apiv1.frozenhu.cn"
	}
})